package com.sgb.member.view_model;

import android.text.TextUtils;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.sgb.member.MemberConfig;
import com.sgb.member.entity.ListMResponse;
import com.sgb.member.entity.MemberServiceListBean;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

public class CompanyServiceViewModel extends ViewModel {
    public MutableLiveData<Boolean>  isLoadDialogLiveData = new MutableLiveData();
    public MutableLiveData<List<CommonPopEntity>>  allTabDataLiveData = new MutableLiveData();
    public MutableLiveData<Boolean>  isEmptyLiveData = new MutableLiveData();
    public MutableLiveData<List<MemberServiceListBean>>  listLiveData = new MutableLiveData();
    // 企业服务
    public void getEnterpriseServicesType() {
        MemberConfig.getInstance().getApi().getAllEnterpriseServicesType().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, new CommonPopEntity("", "全部"));
                    allTabDataLiveData.postValue(data.getData());
                } else {
                    allTabDataLiveData.postValue(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPopEntity>>> call, Throwable t) {
                super.onFailure(call, t);
            }

        });
    }

    private int current;

    public void getList(boolean isLoadMore, String serviceClass,String mNo11,String mNo12) {
        int currentPage = isLoadMore ? current + 1 : 1;
        isLoadDialogLiveData.postValue(true);
        Map<String, Object> map = new HashMap<>();
        map.put("pageSize", currentPage);
        map.put("limit", 10);
        map.put("asc", false);
        map.put("sortType", 1);
        map.put("serviceClass", serviceClass);
        map.put("serviceCategory", mNo11);
        map.put("serviceItem", mNo12);
        List<String> codes = new ArrayList<>();
        map.put("provinceCode", codes);
        map.put("type", 1); // 发布类型 1 企业 ；2 团队
        MemberConfig.getInstance().getApi().getServiceHallCompanyOrTeamList(map).enqueue(new ICallBack<BaseEntity<ListMResponse<List<MemberServiceListBean>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListMResponse<List<MemberServiceListBean>>> data) {
                current = currentPage;
                int total = data.getData().getPages();
                listLiveData.postValue(data.getData().getList());
              //  fragment.refreshRecycler(data.getData().getList(), isLoadMore, current >= total);
            }

            @Override
            public void onFailure(Call<BaseEntity<ListMResponse<List<MemberServiceListBean>>>> call, Throwable t) {
                super.onFailure(call, t);
                if (!isLoadMore) {
                    isEmptyLiveData.postValue(true);
                }
            }
        });
    }

}
